//
//  HZProtocolVC.m
//  HZTC_YaDeArt
//
//  Created by zeroing on 17/4/11.
//  Copyright © 2017年 HZTC. All rights reserved.
//

#import "HZProtocolVC.h"
#import "HZWebView.h"

@interface HZProtocolVC ()
@property (nonatomic, strong)UIView    *pNavigatorView;
@property (nonatomic, strong)HZWebView *pWebView;
@property (nonatomic, strong)UILabel   *pTitle;

@property (nonatomic, copy)NSString *pTitleName;
@property (nonatomic, copy)NSString *pUrl;
@end

@implementation HZProtocolVC

- (void)viewDidLoad {
    [super viewDidLoad];
    self.view.backgroundColor = kMYHexToRGB(0xf0f0f0, 1.0);
    
    _pWebView = [HZWebView new];
    [self.view addSubview:_pWebView];
    
    [self initNavView];
    [self p_initConstraints];
    
    NSDictionary *dict = self.params;
    if ([dict.allKeys containsObject:@"title"]) {
        _pTitleName = dict[@"title"];
    }
    if ([dict.allKeys containsObject:@"url"]) {
        _pUrl = dict[@"url"];
    }
}

- (void)viewDidAppear:(BOOL)animated{
    [super viewDidAppear:animated];
    [self.navigationController setNavigationBarHidden:YES animated:YES];
    
    [self p_loadWeb];
}

-(UIStatusBarStyle)preferredStatusBarStyle{
    return UIStatusBarStyleLightContent;
}

- (void)initNavView{
    _pNavigatorView = [[UIView alloc] initWithFrame:CGRectMake(0, 0, self.view.frame.size.width, 64)];
    _pNavigatorView.backgroundColor = kMYHexToRGB(0xf85256,1);
    
    UIButton *leftButton = [[UIButton alloc] initWithFrame:CGRectMake(10, 20+(64-25-20)/2, 25, 25)];
    [leftButton setImage:[UIImage imageNamed:@"hd_icon_fh2"] forState:UIControlStateNormal];
    [leftButton addTarget:self action:@selector(leftNarBtnOnClick) forControlEvents:UIControlEventTouchUpInside];
    
    _pTitle = [[UILabel alloc] initWithFrame:CGRectMake((self.view.frame.size.width-200)/2, 20, 200, 44)];
    _pTitle.text = @"注册协议";
    _pTitle.textAlignment = NSTextAlignmentCenter;
    _pTitle.textColor = [UIColor whiteColor];

    [_pNavigatorView addSubview:leftButton];
    [_pNavigatorView addSubview:_pTitle];
    
    [self.view addSubview:_pNavigatorView];
}

- (void)leftNarBtnOnClick{
    [self dismissViewControllerAnimated:YES completion:nil];
}

#pragma mark -
#pragma mark private
- (void)p_initConstraints
{
    [_pWebView mas_makeConstraints:^(MASConstraintMaker *make) {
        make.top.mas_equalTo(_pNavigatorView.mas_bottom);
        make.left.mas_equalTo(self.view);
        make.right.mas_equalTo(self.view);
        make.bottom.mas_equalTo(self.view);
    }];
}

- (void)p_loadWeb
{
    if (_pTitleName) {
        _pTitle.text = _pTitleName;
    }
    [_pWebView loadRequest:[NSURLRequest requestWithURL:[NSURL URLWithString:_pUrl]]];
}

-(void)setVCTitle:(NSString *)titleName{
    self.title = titleName;
}

@end
